#include "timerClass.h"

timerClass::timerClass(int periodIN, graphClass *ownerIN, bool startedIN)
{
	period = periodIN;
	started = startedIN;
	owner = ownerIN;
	if (started)
	{
		timerID = timeSetEvent(period, 0,timerProc,(DWORD_PTR)owner,TIME_PERIODIC);
	}
}

timerClass::~timerClass()
{
	if (started)
	{
		timeKillEvent(timerID);
	}
}

int timerClass::getPeriod()
{
	return this->period;
}

bool timerClass::isStarted()
{
	return this->started;
}

void timerClass::startCount()
{
	if (!started)
	{
		timerID = timeSetEvent(period, 0,timerProc,(DWORD_PTR)owner,TIME_PERIODIC);
		started = true;
	}
}

void timerClass::stopCount()
{
	if (started)
	{
		timeKillEvent(timerID);
		started = false;
	}
}

void CALLBACK timerClassProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)	//make it belong to class?
{
		((graphClass*)dwUser)->loadValue();		
}